package com.drerp.autenticacao;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.drerp.RH.Colaborador;
import com.drerp.RH.HorasTrabalho;
import com.drerp.RH.Usuario;
import com.drerp.util.Constantes;

/**
 * Application Lifecycle Listener implementation class SessionListener
 *
 */
public class SessionListener implements HttpSessionListener {

    /**
     * Default constructor. 
     */
    public SessionListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see HttpSessionListener#sessionCreated(HttpSessionEvent)
     */
    public void sessionCreated(HttpSessionEvent arg0) {
        // TODO Auto-generated method stub
    }

	/**
     * @see HttpSessionListener#sessionDestroyed(HttpSessionEvent)
     */
    public void sessionDestroyed(HttpSessionEvent se) {
    	HttpSession session = se.getSession();
    	
    	Usuario usuario = (Usuario) session.getAttribute(Constantes.USER_SESSION_KEY);
		
		if (usuario instanceof Colaborador) {
			((Colaborador) usuario).registrarSaida();
		}
		
		System.out.println(">> Sessão encerrada");
    }
	
}
